What is flat-cache?
The flat-cache package is a simple disk-based key-value store that allows you to set and get data, cache it on disk, and clear the cache when necessary. It is useful for caching results of expensive operations, storing configuration, or any other use case where a simple persistent key-value store is needed.
What are flat-cache's main functionalities?
Caching data to disk
This feature allows you to cache data to disk by setting a key-value pair and then saving the cache. The data can be retrieved later, even after the process is restarted.
const flatCache = require('flat-cache');
let cache = flatCache.load('myCache');
cache.setKey('key', 'value');
cache.save();
Loading cached data from disk
This feature allows you to load previously saved cache from disk and retrieve the value associated with a specific key.
const flatCache = require('flat-cache');
let cache = flatCache.load('myCache');
let value = cache.getKey('key');
Removing a specific key from the cache
This feature allows you to remove a specific key from the cache and then save the updated cache to disk.
const flatCache = require('flat-cache');
let cache = flatCache.load('myCache');
cache.removeKey('key');
cache.save();
Clearing the entire cache
This feature allows you to clear the entire cache and then save the empty cache to disk, effectively resetting it.
const flatCache = require('flat-cache');
let cache = flatCache.load('myCache');
cache.clearAll();
cache.save();
Other packages similar to flat-cache
node-cache
node-cache is an in-memory caching module. It is similar to flat-cache in providing simple key-value storage, but it does not persist the cache to disk by default.
memory-cache
memory-cache is another in-memory key-value store that is similar to flat-cache. It is designed for caching objects in memory and does not include built-in disk persistence.
localforage
localforage is a fast and simple storage library for JavaScript. It improves upon flat-cache by providing a more powerful API and support for IndexedDB, WebSQL, and localStorage, which can be used for client-side storage in web applications.
keyv
keyv is a simple key-value storage with support for multiple backends, including MongoDB, SQLite, PostgreSQL, and more. Unlike flat-cache, keyv is more versatile due to its support for various storage adapters.